//
//  MineAccountHeaderView.m
//  ShowYork
//
//  Created by hxh on 2020/8/26.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "MineAccountHeaderView.h"

@interface MineAccountHeaderView ()
@property (nonatomic,strong)UIImageView *headerImgView;
@property (nonatomic,strong)UIImageView *photoImgView;
@property (nonatomic,strong)UILabel *userId;
@end

@implementation MineAccountHeaderView

- (instancetype)init{
    if (self = [super init]) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    
    self.frame = CGRectMake(0, 0, kScreenW, 130);
    self.backgroundColor = RGBA(248, 248, 248, 1);
    self.headerImgView = [[UIImageView alloc]init];
    self.headerImgView.layer.cornerRadius = 35;
    self.headerImgView.layer.masksToBounds = YES;
    [self addSubview:self.headerImgView];
    
    [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(70,70)).priorityHigh();
        make.top.equalTo(self).offset(15);
        make.centerX.equalTo(self);
    }];
    
    self.userId = [[UILabel alloc]init];
    self.userId.textColor = C51;
    self.userId.font = font(14);
    [self addSubview:self.userId];
    
    [self.userId mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerImgView.mas_bottom).offset(15);
        make.centerX.equalTo(self.headerImgView);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    self.photoImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_photo_tag"]];
    [self addSubview:self.photoImgView];
    self.photoImgView.hidden = YES;
    [self.photoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.equalTo(self.headerImgView);
    }];
    
    self.headerImgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(updateUserInfoIcon)];
    [self.headerImgView addGestureRecognizer:tap];
    
    
}

- (void)updateUserInfo:(UserInfoModel *)userInfo{
    self.userId.text = [NSString stringWithFormat:@"ID：%@",userInfo.id];

    if ([userInfo.id isEqualToNumber:[RPAppManager getCustomerId]]) {
        self.photoImgView.hidden = NO;
    }
    
    if (userInfo.imagePath.length == 0) {
        if (userInfo.sex.intValue == 0) {
            self.headerImgView.image = [UIImage imageNamed:@"defaut_header"];
        }else if (userInfo.sex.intValue == 1){
            self.headerImgView.image = [UIImage imageNamed:@"common_boy_tag"];
        }else{
            self.headerImgView.image = [UIImage imageNamed:@"common_girl_tag"];
        }
    }else{
        [self.headerImgView sd_setImageWithURL:[NSURL URLWithString:userInfo.imagePath] placeholderImage:[UIImage imageNamed:@"defaut_header"]];
    }
  }

- (void)updateUserInfoIcon{
    if (self.delegate && [self.delegate respondsToSelector:@selector(updateHeaderInfoIcon)]) {
        [self.delegate updateHeaderInfoIcon];
    }
}


@end
